home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 741 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: ida.his.se!a95hanne
  2. From: a95hanne@ida.his.se (Hannu Nevalainen)
  3. Newsgroups: comp.lang.c,alt.msdos.programmer
  4. Subject: Re: Two strange C problems.
  5. Followup-To: comp.lang.c,alt.msdos.programmer
  6. Date: 8 Jan 1996 23:15:40 GMT
  7. Organization: University of Skoevde
  8. Distribution: world
  9. Message-ID: <4cs8is$p4s@mhost.ida.his.se>
  10. References: <4cojb2$qog@lugb.latrobe.edu.au>
  11. NNTP-Posting-Host: oden.ida.his.se
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. Gregary John Boyles (cs102238@lux.latrobe.edu.au) wrote:
  15. : I have two C problems.
  16.  
  17. : PROBLEM 1 :
  18.  
  19. <snip, snip>
  20.  
  21. : PROBLEM 2 :
  22.  
  23. : const escape=27;
  24. : const cr=13;
  25. : const bs=8;
  26.  
  27. : while (ch!=cr)
  28. : {
  29. :      .
  30. :      .
  31. :      .
  32. : }
  33.  
  34. : while (ch!=escape)
  35. : {
  36. :      .
  37. :      .
  38. :      .
  39. : }
  40.  
  41. : If I replace the 27 with \27' or the 13 with '\13' then these loops don't
  42. : work i.e. an infinite loop results. WHY?
  43.  
  44.  You will most probably get the numbers 'interpreted' as OCTAL values. 
  45. That's the default, if I'm not too wrong. At least it is if one types 
  46. \033 which would be decimal 27 (ESC). I one types \x1b then one would be 
  47. using hexadecimal (the example equals ESC again).
  48.  
  49. : Also if I want to do somthing like this : puts("\24 \25"); which should
  50. : print the up and down arrows on the screen (ASCII 24 and 25), but no, it
  51. : prints some other ASCII characters. As far as I can tell C has its own
  52. : unique character table, at least for the control characters. WHY?
  53.  
  54. : Sometimes I wonder whether some one needs to go back an rewrite the damn
  55. : language so that it works sensibly and predictably like Pascal can be
  56. : relied upon to do.
  57.  
  58.  
  59.  In my opinion; sorry  but - you have some reading to do.
  60.  
  61.  "The C Programming Language" by B W Kernighan/D M Ritchie is a good 
  62. reference book. While there are some teaching attempts there are better 
  63. books of that kind. (ISBN 0-13-110362-8, second ed.)
  64.  
  65.  Pascal puts up a lot of hindrance that simply isn't there in C.
  66.  (My opinion again ;-)
  67.  
  68. /Hannu
  69. --     _                                       __
  70.   _   //        Simplicity is the point,  | | |   | | | /
  71.   \\ // Amiga     versatiliy helps.       |-| |-  |\| |/
  72.    \X/"mainiac"  a95hanne@ida.his.se      | |.|__.| |.| \.
  73.  
  74.   Running an Amiga; '030 @50Mhz, '882 @50MHz, 10M RAM & 400M HD
  75.  
  76.  "Life starts at '030, fun starts at '040, impotence starts at '86." 
  77.